package com.supergzt.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.supergzt.annotation.RequiresLogin;
import com.supergzt.context.SecurityContextHolder;
import com.supergzt.entity.dos.Bill;
import com.supergzt.entity.base.Result;
import com.supergzt.entity.vos.BillQueryVo;
import com.supergzt.service.BillService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/bill")
public class BillController {

	@Resource
	private BillService billService;

	@GetMapping
	@RequiresLogin
	public Result<?> getBillPage(Page<Bill> page){
		return Result.success(billService.page(page));
	}

	@GetMapping("query")
	@RequiresLogin
	public Result<?> queryBill(BillQueryVo billQueryVo,Page<Bill> page){
		return Result.success(billService.queryBills(billQueryVo,page));
	}

	@PostMapping
	@RequiresLogin
	public Result<?> insertBill(@RequestBody Bill bill){
		billService.save(bill.setUserId(SecurityContextHolder.getUserId()).setBillTime(LocalDate.now()));
		return Result.ok();
	}

	@DeleteMapping
	@RequiresLogin
	public Result<?> deleteBill(@RequestParam("ids") List<Long> ids){
		billService.removeByIds(ids);
		return Result.ok();
	}
}
